<?php
$auth = Auth::getAuth('current_user');
$db = new Database;
$fs = new functions;
$search = new Search();
if(isset($_POST['action'])){

	$date = $fs->currentDateTime();
	switch($_POST['action']){
		
		case "landing_page":
			$url = $_POST['param_url'];
			$insert = array("page"		=>	$url,
					"date_set"	=>	$date,
					"userID"	=>	$auth['id'],
					"is_active"	=>	"1");
			$getPage = $db->query("SELECT * FROM page_settings WHERE userID={$db->escape($auth['id'])} AND is_active={$db->escape(1)}","row");
			if($getPage['userID']==$auth['id']){
				$condition = array("userID"	=>	$auth['id']);
				$last_settings = $db->update("page_settings",$insert,$condition);
			}else{
				$last_settings = $db->insert("page_settings",$insert);
			}
			
			$ret = array("noti"	=>	"Page was successfully set.");
			echo json_encode($ret);
			
		break;
	
		case "landing_page_remove":
			$condition = array("userID"	=>	$auth['id']);
			$last_settings = $db->update("page_settings",array("is_active"	=>	"0"),$condition);
			$ret = array("noti"	=>	"Page was successfully remove.");
			echo json_encode($ret);
			
		break;
	// Save location of user logged in
		case "getLocation":
			$id = $_POST['id'];
			$getLoc = $db->query("SELECT * FROM tblocation WHERE userID={$db->escape($id)} AND is_active={$db->escape(1)}","array");
			foreach($getLoc as $loc){
				
			}
			echo $loc['location'];
		break;
	
	// Save Notifications
		case "saveNotifications":
			$json_details = $_POST['json_details'];
			
			$insert = array("json"		=>	$json_details,
					"user_id"	=>	$auth['id'],
					"company_id"	=>	$auth['company_id'],
					"date"		=>	$date,
					"type"		=>	"notifications",
					"is_active"	=>	"1");
			
			$get_privacy = $db->query("SELECT * FROM tbprivacy WHERE user_id={$db->escape($auth['id'])} AND type={$db->escape('notifications')}","numrows");
			
			if($get_privacy!=0){
				$db->update("tbprivacy",$insert,array("user_id"=>$auth['id'],"type"=>"notifications"));
				echo "Updated.";
			}else{
				$db->insert("tbprivacy",$insert);
				echo "Done.";
			}
	}
	
	
	
}

?>
